package org.bees.cms.core.io;

import java.io.File;

import org.bees.cms.common.Files;
import org.bees.cms.common.Transformable;
import org.bees.cms.core.Domain;
import org.bees.cms.core.Named;

public abstract class IO extends Domain implements Named, Transformable<File> {
	private static final long serialVersionUID = -7840213792860899109L;

	protected File file;
	protected String name;
	protected String path;
	protected Boolean flag;

	public IO() {
		super();
	}

	public IO(String path) throws Exception {
		super();
		from(new File(Files.absolute(path)));
	}

	public abstract long size() throws Exception;

	public abstract void save() throws Exception;

	public abstract void omit() throws Exception;

	public abstract void name(String name) throws Exception;

	public abstract void move(String path) throws Exception;

	public abstract void copy(String path) throws Exception;

	public abstract void hide() throws Exception;

	public abstract void show() throws Exception;

	@Override
	public void from(File t) throws Exception {
		file = t;
		name = t.getName();
		path = Files.relate(t.getPath());
	}

	@Override
	public File to() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Boolean getFlag() {
		return flag;
	}

	public void setFlag(Boolean flag) {
		this.flag = flag;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		IO other = (IO) obj;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}

}
